Skip to content

sso flow#22

Merged
gdauber1 merged 3 commits intomainfrom
sso_with_user_id
Aug 17, 2025
Merged

sso flow#22
gdauber1 merged 3 commits intomainfrom
sso_with_user_id

Conversation

@gdauber1
Copy link
Collaborator

No description provided.

@claude
Copy link

claude bot commented Aug 16, 2025

Claude finished @gdauber1's task —— View job


Code Review for PR #22: SSO Flow

I've reviewed the changes to src/modules/auth.ts and have the following feedback:

Summary of Changes

The PR modifies the getSsoAccessToken method to accept a userid parameter and includes it in the API endpoint path:

  • Previous: /apps/${appId}/auth/sso/accesstoken
  • New: /apps/${appId}/auth/sso/accesstoken/${userid}

Review Findings

🚨 Critical Issues

  1. Breaking Change Without Version Bump

    • This is a breaking API change that modifies the method signature from getSsoAccessToken() to getSsoAccessToken(userid)
    • Any existing code calling this method will break
    • The package version should be updated accordingly (major version bump for breaking changes)
  2. Security Concerns

    • The userid parameter is directly interpolated into the URL without validation
    • Consider validating the userid format to prevent potential injection attacks
    • Example validation:
    if (!userid || typeof userid !== 'string' || !userid.trim()) {
      throw new Error('Invalid userid parameter');
    }

⚠️ Code Quality Issues

  1. Inconsistent Documentation Style

    • The JSDoc comment uses @param {string} userid which is JavaScript style
    • The codebase is TypeScript, so the type annotation in JSDoc is redundant
    • Consider updating to: @param userid - User ID to include as path parameter
  2. Poor Commit Message

    • The commit message "init" is not descriptive
    • Should describe what changed, e.g., "feat: add userid parameter to getSsoAccessToken method"

📋 Missing Items

  1. No Tests

    • No tests were added or updated for this change
    • The getSsoAccessToken method has no test coverage at all
    • Tests should verify:
      • Valid userid parameter handling
      • Error cases (missing/invalid userid)
      • Correct URL construction
  2. No PR Description

    • The PR lacks a description explaining:
      • Why this change is needed
      • What problem it solves
      • Migration guide for existing users

Good Practices

  1. The variable extraction (const url = ...) improves readability
  2. TypeScript type annotation is properly added

Recommendations

  1. Add input validation for the userid parameter
  2. Add comprehensive tests for the modified method
  3. Update the PR description with context and migration guide
  4. Consider backwards compatibility - perhaps make userid optional with a deprecation warning
  5. Update package version appropriately for this breaking change
  6. Add error handling for invalid userid values

Example improvement:

async getSsoAccessToken(userid: string) {
  if (!userid || typeof userid !== 'string' || !userid.trim()) {
    throw new Error('getSsoAccessToken: userid parameter is required and must be a non-empty string');
  }
  
  const url = `/apps/${appId}/auth/sso/accesstoken/${encodeURIComponent(userid)}`;
  return axios.get(url);
}

This is a functional change but needs proper documentation, testing, and security considerations before merging.

@github-actions
Copy link

github-actions bot commented Aug 16, 2025

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.5.0-pr.22.fa8451c

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.5.0-pr.22.fa8451c"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.5.0-pr.22.fa8451c"
  }
}

Preview published to npm registry — try new features instantly!

@claude
Copy link

claude bot commented Aug 16, 2025

Claude finished @gdauber1's task —— View job


Code Review for PR #22: SSO Flow

I've completed a thorough review of the changes in this pull request. Here are my findings:

Review Checklist

  • Read CLAUDE.md for repo-specific guidelines
  • Analyze src/modules/auth.ts changes
  • Analyze src/client.ts changes
  • Review code quality and best practices
  • Check for potential bugs or issues
  • Evaluate security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Summary of Changes

This PR makes two key changes:

  1. src/modules/auth.ts: Modified getSsoAccessToken method to accept a required userid parameter and include it in the API endpoint path
  2. src/client.ts: Added the auth module to the serviceRoleModules object

🚨 Critical Issues

1. Breaking API Change

  • The getSsoAccessToken method signature changed from getSsoAccessToken() to getSsoAccessToken(userid: string)
  • This is a breaking change that will cause runtime errors for any existing code calling this method without parameters
  • The package version (0.5.0) doesn't reflect this breaking change - should be bumped to 1.0.0 following semver

2. Security Vulnerability

  • The userid parameter is directly interpolated into the URL without validation or encoding
  • This could lead to path injection attacks if the userid contains special characters
  • Fix: Use encodeURIComponent() to properly encode the parameter:
    const url = `/apps/${appId}/auth/sso/accesstoken/${encodeURIComponent(userid)}`;

3. No Test Coverage

  • The getSsoAccessToken method has zero test coverage in both unit and E2E tests
  • Critical security-related methods like this should have comprehensive test coverage
  • Missing tests for:
    • Valid userid scenarios
    • Invalid/empty userid handling
    • Special character encoding
    • Error responses

⚠️ Code Quality Issues

1. Inconsistent Documentation Style

  • The JSDoc uses @param {string} userid which is JavaScript style
  • In TypeScript, the type annotation in JSDoc is redundant
  • Should be: @param userid - User ID to include as path parameter

2. Poor Commit Messages

  • Commit message "init" is not descriptive
  • Should follow conventional commits: feat: add userid parameter to getSsoAccessToken
  • Second commit "add_auth_under_serviceRoleModules" uses underscores instead of proper formatting

3. Missing Input Validation

  • No validation that userid is non-empty or properly formatted
  • Should validate before making the API call:
    if (!userid || typeof userid !== 'string' || !userid.trim()) {
      throw new Error('getSsoAccessToken: userid parameter is required and must be a non-empty string');
    }

📋 Missing Documentation

  • No PR description explaining why this change is needed
  • No migration guide for users upgrading from previous version
  • No context about what problem this solves or why userid is now required

🔍 Performance Considerations

  • The change itself has minimal performance impact
  • URL construction with template literals is efficient
  • However, missing input validation could lead to unnecessary API calls with invalid data

✅ Positive Aspects

  1. The variable extraction (const url = ...) improves code readability
  2. TypeScript type annotation is properly added to the parameter
  3. The auth module addition to serviceRoleModules provides consistency

🛠️ Recommendations

  1. Add comprehensive input validation and encoding:

    async getSsoAccessToken(userid: string) {
      if (!userid || typeof userid !== 'string' || !userid.trim()) {
        throw new Error('getSsoAccessToken: userid is required and must be a non-empty string');
      }
      const url = `/apps/${appId}/auth/sso/accesstoken/${encodeURIComponent(userid)}`;
      return axios.get(url);
    }
  2. Add test coverage in tests/unit/auth.test.js

  3. Update package version to 1.0.0 for this breaking change

  4. Add migration documentation in the PR description

  5. Consider backwards compatibility - perhaps make userid optional with deprecation warning

  6. Fix the service role auth module - it's currently using the regular axios client instead of the service role client

🐛 Bug in client.ts

The auth module in serviceRoleModules is using the wrong axios clients:

auth: createAuthModule(axiosClient, functionsAxiosClient, appId),

Should be:

auth: createAuthModule(serviceRoleAxiosClient, serviceRoleFunctionsAxiosClient, appId),

This bug means service role auth operations won't use the service token properly.

Conclusion

While the changes are functional, they introduce breaking changes and security vulnerabilities that need to be addressed before merging. The lack of tests and documentation makes this PR risky to merge in its current state.

@claude
Copy link

claude bot commented Aug 16, 2025

Claude finished @gdauber1's task —— View job


Code Review for PR #22: SSO Flow

I've reviewed the latest changes in this pull request. Here's my comprehensive feedback:

Summary of Changes

The PR has been significantly refactored since the previous reviews:

  1. Removed getSsoAccessToken from auth.ts - The problematic method has been completely removed
  2. Created new sso.ts module - SSO functionality moved to a dedicated module with getAccessToken method
  3. Updated client.ts - Added the SSO module to service role modules and fixed the auth module bug

✅ Improvements Since Last Review

  1. Fixed Critical Bug: The auth module in serviceRoleModules now correctly uses the regular axios clients (not service role), which is appropriate since auth operations should use user tokens
  2. Better Module Organization: SSO functionality is now properly separated into its own module
  3. Cleaner API: The method is now simply getAccessToken instead of getSsoAccessToken

🚨 Critical Issues Remain

1. Security Vulnerability - No Input Validation/Encoding

The userid parameter is still directly interpolated into the URL without validation or encoding:

const url = `/apps/${appId}/auth/sso/accesstoken/${userid}`;

Fix Required:

async getAccessToken(userid: string) {
  if (!userid || typeof userid !== 'string' || !userid.trim()) {
    throw new Error('getAccessToken: userid is required and must be a non-empty string');
  }
  const url = `/apps/${appId}/auth/sso/accesstoken/${encodeURIComponent(userid)}`;
  return axios.get(url);
}

2. Breaking Change Without Version Bump

  • The SSO functionality has been moved and the API changed
  • Package version remains at 0.5.0
  • This should be a major version bump (1.0.0) per semver

3. Zero Test Coverage

  • No tests exist for the new SSO module
  • Critical security functionality like this must have comprehensive test coverage
  • Missing tests for: valid userid, invalid/empty userid, special characters, error handling

⚠️ Code Quality Issues

  1. Inconsistent Documentation Style

    • Uses @param {string} userid which is JavaScript style in a TypeScript file
    • Should be: @param userid - User ID for SSO access token
  2. Poor Commit Messages

    • "init", "sso_module", "add_auth_under_serviceRoleModules" are not descriptive
    • Should follow conventional commits format
  3. No PR Description

    • Still missing context about why these changes are needed
    • No migration guide for users

📋 Architecture Concerns

  1. SSO Module Placement

    • SSO is only available under asServiceRole, not for regular users
    • Is this intentional? Most SSO flows are user-initiated
    • Consider if SSO should also be available in user modules
  2. Return Type Not Specified

    • The getAccessToken method doesn't specify its return type
    • Should be: async getAccessToken(userid: string): Promise<AxiosResponse<{access_token: string}>>

🛠️ Recommendations

  1. Add Input Validation and Encoding (see fix above)

  2. Add Comprehensive Tests:

    describe('SSO Module', () => {
      test('should get access token with valid userid', async () => {
        // Test implementation
      });
      
      test('should encode special characters in userid', async () => {
        // Test with userid containing spaces, slashes, etc.
      });
      
      test('should throw on empty userid', async () => {
        // Test validation
      });
    });
  3. Update Version: Change to 1.0.0 in package.json

  4. Add TypeScript Return Type

  5. Document the Change: Add a migration guide in the PR description

Performance & Security Considerations

  • Performance: Changes have minimal impact, simple HTTP GET request
  • Security: Critical path injection vulnerability must be fixed before merging
  • Error Handling: Consider wrapping in try-catch for better error messages

Conclusion

While the refactoring improves the architecture by separating SSO concerns, the critical security vulnerability and lack of tests make this PR unsafe to merge in its current state. The breaking changes also require proper versioning and documentation.

Status: Changes requested - security fix and tests are mandatory before approval.

@claude
Copy link

claude bot commented Aug 16, 2025

Claude finished @gdauber1's task —— View job


Code Review for PR #22: SSO Flow

I've completed my review of the latest changes in this pull request. Here's my comprehensive feedback:

Review Checklist

  • Read CLAUDE.md for repo-specific guidelines
  • Analyze src/modules/sso.ts (new file)
  • Analyze src/modules/auth.ts changes
  • Analyze src/client.ts changes
  • Check for test coverage
  • Provide comprehensive review feedback

Summary of Changes

  1. Removed getSsoAccessToken() from auth.ts - Previous implementation without userid parameter removed
  2. Created new sso.ts module - SSO functionality moved to dedicated module with getAccessToken(userid) method
  3. Updated client.ts - Added SSO module to service role modules only (not available to regular users)

🚨 Critical Security Vulnerability

The userid parameter in sso.ts:20 is directly interpolated into the URL without any validation or encoding:

const url = `/apps/${appId}/auth/sso/accesstoken/${userid}`;

Security Risk: This creates a path injection vulnerability. Malicious input like ../../../admin could potentially access unauthorized endpoints.

Required Fix:

async getAccessToken(userid: string) {
  if (!userid || typeof userid !== 'string' || !userid.trim()) {
    throw new Error('getAccessToken: userid is required and must be a non-empty string');
  }
  const url = `/apps/${appId}/auth/sso/accesstoken/${encodeURIComponent(userid)}`;
  return axios.get(url);
}

⚠️ Code Quality Issues

  1. Inconsistent Documentation Style

    • Uses JavaScript-style JSDoc (@param {string} userid) in TypeScript files
    • Should be: @param userid - User ID for SSO access token
  2. Missing Return Type Annotations

    • getAccessToken method doesn't specify return type
    • Should be: async getAccessToken(userid: string): Promise<AxiosResponse>
  3. Poor Commit Messages

    • "init", "sso_module", "add_auth_under_serviceRoleModules" are not descriptive
    • Should follow conventional commits: feat(sso): add userid parameter to SSO access token endpoint

🚨 Breaking Change Without Version Bump

  • SSO functionality has been moved and API changed (now requires userid parameter)
  • Package version remains at 0.5.0
  • This is a breaking change requiring major version bump to 1.0.0 per semver

📋 Missing Test Coverage

  • Zero tests for the new SSO module
  • No tests verify:
    • Valid userid handling
    • Invalid/empty userid rejection
    • URL encoding of special characters
    • Error response handling
  • Critical security functionality must have comprehensive test coverage

🤔 Architecture Concerns

  1. SSO Only in Service Role

    • SSO is only available via client.asServiceRole.sso
    • Most SSO flows are user-initiated, not service-role operations
    • Consider if SSO should also be available in regular user modules
  2. Removed Auth Module from Service Role

    • Auth module is not included in serviceRoleModules (line 88)
    • This might be intentional but worth confirming

✅ Positive Aspects

  1. Better Module Organization - SSO separated into its own module
  2. Cleaner API - Method renamed from getSsoAccessToken to getAccessToken
  3. Proper Service Role Setup - Uses correct service role axios client

🛠️ Recommendations

  1. Immediate Security Fix (see required fix above)
  2. Add Comprehensive Tests:
    describe('SSO Module', () => {
      test('should encode special characters in userid', async () => {
        const userid = 'user@example.com/../../admin';
        // Verify URL encoding prevents path traversal
      });
      
      test('should reject empty userid', async () => {
        await expect(sso.getAccessToken('')).rejects.toThrow();
      });
    });
  3. Update Package Version to 1.0.0
  4. Add PR Description explaining the change and migration path
  5. Consider TypeScript Improvements:
    interface SsoModule {
      getAccessToken(userid: string): Promise<AxiosResponse<{access_token: string}>>;
    }

Performance Considerations

  • Minimal performance impact
  • Single HTTP GET request
  • Consider adding request caching if same userid is requested multiple times

Conclusion

While the refactoring improves code organization, the critical security vulnerability makes this PR unsafe to merge. The lack of tests and proper versioning are also significant concerns that must be addressed.

Status: Changes requested - security fix and tests are mandatory before approval.

/**
* Get current user sso access token
* @param {string} userid - User ID to include as path parameter
* @returns {Promise<Object>} Current user sso access_token
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the types in the jsdoc, they'll come from typescript.
Wanna add the type of the response? is it Promise<{ access_token: string }>?

@gdauber1 gdauber1 merged commit 8a976d0 into main Aug 17, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants